package com.ht.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ht.mapper.EmpMapper;
import com.ht.pojo.UserRecord;
import com.ht.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author d
 * @version 1.0
 * @description: TODO
 * @date 2021/7/17 14:16
 */
@Service
public class EmpServiceImpl implements EmpService{

    @Autowired
    private EmpMapper empMapper;

    @Override
    public PageResult getUserList(PageResult pageResult) {
        IPage ipage = new Page(pageResult.getPageNum(),pageResult.getPageSize());
        QueryWrapper queryWrapper = new QueryWrapper();
        boolean flag = StringUtils.hasLength(pageResult.getQuery());
        queryWrapper.like(flag,"cu_id",pageResult.getQuery());
        ipage = empMapper.selectPage(ipage,queryWrapper);
        long total = ipage.getTotal();
        List<UserRecord> rows =  ipage.getRecords();
        return pageResult.setRows(rows).setTotal(total);
    }

    @Override
    public void updateStatus(UserRecord userRecord) {
        empMapper.updateById(userRecord);
    }

    @Override
    public void saveaddUser(UserRecord userRecord) {
        empMapper.insert(userRecord);
    }

    @Override
    public UserRecord selectUser(Integer id) {
        return empMapper.selectById(id);
    }

    @Override
    public void updateUser(UserRecord userRecord) {
        empMapper.updateById(userRecord);
    }
}
